<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('teleMarketing.no1')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('teleMarketing.no2')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    
    <el-tabs v-model="activeName">
        <el-tab-pane :label="$t('teleMarketing.no51')" name="1">
            <!-- -------------搜索查询栏------------------------ -->
            <search 
                :searchData="searchData1" 
                @search="search1" 
                :searchRight="true"
                :outputRight="false"
            ></search>
            <!-- -------------搜索查询栏------------------------ -->
            <div class="list_operation" >
                <el-button v-if="$store.state.common.permiss.telemarketlist.includes('import')" type="primary" @click="showaddData">+{{$t('teleMarketing.no21')}}</el-button>
                <el-button v-if="$store.state.common.permiss.telemarketlist.includes('distribution')" type="primary" @click="distribution">{{$t('OutsourcedManage.no14')}}</el-button>
            </div>
            <div class="table" v-if="true">
                <el-table :data="listData1" size="small" v-loading="loadFlag" stripe @selection-change="handleSelectionChange1">
                    <el-table-column type="selection"  width="55">
                    </el-table-column>
                    <el-table-column align="center" prop="phone" :label="$t('public.userTel')">
                    </el-table-column>
                    <el-table-column align="center" prop="name" :label="$t('public.name')">
                    </el-table-column>
                    <el-table-column align="center" prop="idCard" :label="$t('public.no2')">
                    </el-table-column>
                    <el-table-column align="center" prop="createTime" :label="$t('public.no21')" width="86">
                    </el-table-column>
                    <el-table-column align="center" prop="unorderedDay" :label="$t('teleMarketing.no47')">
                    </el-table-column>
                    <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="120">
                        <template slot-scope="scope">
                        <span v-if="$store.state.common.permiss.telemarketlist.includes('detail')" class="table_opr" @click="selectDetail(scope.row.id,scope.row.name,scope.row.phone)">
                        {{$t('public.no29')}}
                        </span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- ------------  分页显示栏  ------------------------ -->
                <el-row type="flex" justify="end">
                <div class="pages" >
                    <el-pagination
                    @current-change="listHandleCurrentChange1"
                    :current-page="pagination1.current"
                    layout="sizes, prev, pager, next, total,->"
                    :page-sizes="pagination1.pageSizeOptions"
                    :page-size="pagination1.pageSize"
                    @size-change="listHandleSizeChange1"
                    :total="pagination1.total">
                    </el-pagination>
                </div>
                </el-row>
            </div>
        </el-tab-pane>
        <el-tab-pane :label="$t('teleMarketing.no52')" name="2">
            <!-- -------------搜索查询栏------------------------ -->
            <search 
                :searchData="searchData2" 
                @search="search2" 
                @putExcel="putExcel" 
                :searchRight="true"
                :outputRight="$store.state.common.permiss.telemarketlist.includes('export')"
            ></search>
            <div class="list_operation" >
                <el-button v-if="$store.state.common.permiss.telemarketlist.includes('import')" type="primary" @click="showaddData">{{$t('teleMarketing.no21')}}</el-button>
                <el-button v-if="$store.state.common.permiss.telemarketlist.includes('transfer')" type="primary" @click="todayRedeploy">{{$t('loanAfterManage.redeploy')}}</el-button>
            </div>
            <!-- -------------表单显示栏------------------------ -->
            <div class="table" v-if="true">
                <el-table :data="listData2" size="small" v-loading="loadFlag" stripe @selection-change="handleSelectionChange2">
                    <el-table-column type="selection"  width="55">
                    </el-table-column>
                    <el-table-column align="center" prop="phone" :label="$t('public.userTel')">
                    </el-table-column>
                    <el-table-column align="center" prop="name" :label="$t('public.name')">
                    </el-table-column>
                    <el-table-column align="center" prop="idCard" :label="$t('public.no2')">
                    </el-table-column>
                    <el-table-column align="center" prop="adminUpdateTime" :label="$t('teleMarketing.no48')">
                    </el-table-column>
                    <el-table-column align="center" prop="adminName" :label="$t('teleMarketing.no7')">
                    </el-table-column>
                    <el-table-column align="center" prop="followUpStatus" :label="$t('teleMarketing.no9')">
                      <template slot-scope="scope">
                        <span>{{$t($store.getters.isNo_status(scope.row.followUpStatus))}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="finalFollowupTime" :label="$t('teleMarketing.no59')">
                    </el-table-column>
                    <el-table-column align="center" prop="unfollowupDay" :label="$t('teleMarketing.no50')">
                    </el-table-column>
                    <el-table-column align="center" prop="phoneResult" :label="$t('auditDetail.no43')" >
                      <template slot-scope="scope">
                        <span>{{$t($store.getters.tel_through(scope.row.phoneResult))}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="isBorrow" :label="$t('teleMarketing.no14')">
                      <template slot-scope="scope">
                        <span>{{$t($store.getters.loanIntention_status(scope.row.isBorrow))}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column align="center" prop="applyTime" :label="$t('public.CreateDate')">
                    </el-table-column>
                    <el-table-column align="center" prop="loanTime" :label="$t('teleMarketing.no11')">
                    </el-table-column>
                    <el-table-column align="center" prop="orderSuccessCount" :label="$t('teleMarketing.no49')">
                    </el-table-column>
                    <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="120">
                        <template slot-scope="scope">
                        <span v-if="$store.state.common.permiss.telemarketlist.includes('detail')" class="table_opr"  @click="selectDetail(scope.row.id,scope.row.name,scope.row.phone)">
                        {{$t('public.no29')}}
                        </span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- ------------  分页显示栏  ------------------------ -->
                <el-row type="flex" justify="end">
                <div class="pages" >
                    <el-pagination
                    @current-change="listHandleCurrentChange2"
                    :current-page="pagination2.current"
                    layout="sizes, prev, pager, next, total,->"
                    :page-sizes="pagination2.pageSizeOptions"
                    :page-size="pagination2.pageSize"
                    @size-change="listHandleSizeChange2"
                    :total="pagination2.total">
                    </el-pagination>
                </div>
                </el-row>
            </div>
        </el-tab-pane>
    </el-tabs>

    <div class="foot"></div>

    <!-- ------------------ 点击转派弹窗开始 -------------------- -->
    <el-dialog :title="$t('loanAfterManage.redeploy')" :visible.sync="redeployFlag" width="650px">
      <!-- <div class="left2right">
        <span class="left">{{$t('public.orderId')}}:</span>
        <div class="right">
          {{orderIds.join()}}
        </div>
      </div>
      <div class="left2right">
        <span class="left">{{$t('public.userId')}}:</span>
        <div class="right">
          {{userIds.join()}}
        </div>
      </div> -->
      <div class="left2right">
        <span class="left">{{$t('loanAfterManage.redeployTo')}}:</span>
        <div class="right">
          <el-select size="small" v-model="redeployStatus" :placeholder="$t('public.placeholder')">
            <el-option v-for="item in adminOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="left2right">
        <span class="left">{{$t('loanAfterManage.reason')}}:</span>
        <div class="right">
          <el-input type="textarea" v-model="reason" :placeholder="$t('loanAfterManage.placeholder')+'~'"></el-input>
        </div>
      </div>
      <div class="left2right">
        <span class="left"></span>
        <div class="right">
          <el-button type="primary" size="small" @click="redeploySubmit">{{$t('proManage.sure')}}</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- ------------------ 点击转派弹窗结束 -------------------- -->

    <!-- ------------------ 点击个性分单弹窗开始 -------------------- -->
    <el-dialog :title="$t('add.no75')" :visible.sync="selfdomFlag"  width="900px">
      <p class="form-p mt-10">
        <span class="form-span2">{{$t('teleMarketing.no58')}}：{{this.noallotOrdersNew}}</span>
      </p>
      <el-table :data="tableData2" size="small" style="min-height:240px">
        <el-table-column type="index" :label="$t('serviceManage.index')">
        </el-table-column>
        <el-table-column align="center" prop="name" :label="$t('public.name')" min-width="100">
        </el-table-column>
        <el-table-column align="center" prop="account" :label="$t('OutsourcedManage.no25')" min-width="70">
        </el-table-column>
        <el-table-column align="center" prop="totalUser" :label="$t('teleMarketing.no35')" min-width="70">
        </el-table-column>
        <el-table-column align="center" prop="followedUser" :label="$t('teleMarketing.no36')" min-width="70">
        </el-table-column>
        <el-table-column align="center" prop="notFollowedUser" :label="$t('teleMarketing.no37')" min-width="90">
        </el-table-column>
        <el-table-column align="center" prop="operation" :label="$t('public.operation')" width="220">
          <template slot-scope="scope">
           <div class="mb5">
              <span>{{$t('OutsourcedManage.no24')}}</span>
              <el-input style="width:60px;" size="mini" v-model="inputValueNew[scope.row.adminId]"></el-input>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
          <el-pagination
            @current-change="handleCurrentChange1"
            :current-page="currentPage1"
            layout="prev, pager, next, ->"
            :total="pageTotal1?pageTotal1:0">
          </el-pagination>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="selfdomFlag = false">{{$t('public.no50')}}</el-button>
        <el-button type="primary" @click="selfdomSure">{{$t('public.no49')}}</el-button>
      </span>
      
    </el-dialog>
    <!-- ------------------ 点击个性分单弹窗结束 -------------------- -->

    <!-- ------------------ 查看详情弹窗开始/电销记录 -------------------- -->
    <el-dialog :title="$t('public.no29')" :visible.sync="detailFlag"  width="1000px">
      <p class="form-p mb10">
        <span class="form-span2">{{$t('public.name')}}：</span>
        <span class="mr20">{{detailData.name}}</span>
        <span class="form-span2">{{$t('public.userTel')}}：</span>
        <span class="mr20">{{detailData.phone}}</span>
      </p>
      <el-table :data="tableData3" size="small" style="min-height:240px">
        <el-table-column align="center" prop="createTime" :label="$t('public.no21')">
        </el-table-column>
        <el-table-column align="center" prop="adminName" :label="$t('teleMarketing.no7')">
        </el-table-column>
        <el-table-column align="center" prop="callResult" :label="$t('auditDetail.no43')" >
          <template slot-scope="scope">
              <span>{{$t($store.getters.tel_through(scope.row.callResult))}}</span>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="isSendMessage" :label="$t('operationDetail.no25')" >
          <template slot-scope="scope">
              <span>{{$t($store.getters.isNo_status(scope.row.isSendMessage))}}</span>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="isBorrow" :label="$t('teleMarketing.no14')" >
          <template slot-scope="scope">
              <span>{{$t($store.getters.loanIntention_status(scope.row.isBorrow))}}</span>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="remark" :label="$t('public.no37')" >
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
        <el-pagination
          @current-change="handleCurrentChange3"
          :current-page="currentPage3"
          layout="prev, pager, next, ->"
          :total="pageTotal3?pageTotal3:0">
        </el-pagination>
      </el-row>
      
    </el-dialog>
    <!-- ------------------ 查看详情弹窗结束 -------------------- -->

    <!-- 添加营销数据 -->
    <el-dialog :title="$t('teleMarketing.no12')" :visible.sync="addDataFlag"  width="550px">
        <el-row>
          <span style="font-weight:bold">{{$t('teleMarketing.no53')}}：</span>{{$t('teleMarketing.no55')}} <el-link type="primary" @click="downExcel()">{{$t('teleMarketing.no55')}}</el-link>
        </el-row>
        <el-row v-if="activeName=='2'" class="mt10">
          <span style="font-weight:bold">{{$t('teleMarketing.no70')}}：</span>
          <el-select size="small" v-model="addDataAdmin" :placeholder="$t('public.placeholder')">
            <el-option v-for="item in adminOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-row>
        <div class="box mt15" style="height:80px;">
            <span style="font-weight:bold;float:left;">{{$t('teleMarketing.no56')}}：</span>
            <el-upload :action="fileAction" :http-request="httpRequest" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
                :before-upload="beforeUpload" :on-remove="removeHandler" :on-success="uploadSuccess" ref="upload">
                <!-- <el-button size="small" type="primary">{{$t('teleMarketing.no16')}}</el-button> -->
                <span class="upload">{{$t('teleMarketing.no16')}}</span>
            </el-upload>
            <!-- <el-upload
            :action="fileAction"
            :show-file-list="false"
            accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
            :on-success="handleAvatarSuccess">
            </el-upload> -->
            <div slot="tip" class="el-upload__tip">{{$t('teleMarketing.no57')}}</div>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addDataFlag = false">{{$t('public.no50')}}</el-button>
            <el-button type="primary" @click="addExcel">{{$t('public.no49')}}</el-button>
        </span>
    </el-dialog>

  </div>
</template>
<script>
import putExcel from 'src/mixins/putExcel.js';//导出excel
import telemarketMem from 'src/mixins/telemarketMem.js';//获取电销员下拉
export default {
  name: 'marketing',
  mixins:[putExcel,telemarketMem],
  data () {
    const searchData1=[
      {
        type: 'input',
        label: 'public.userTel',
        attr: 'phone',
        value: ''
      },
      {
        type: 'input',
        label: 'public.name',
        attr: 'name',
        value: ''
      },
      {
        type: 'input',
        label: 'public.no2',
        attr: 'idCard',
        value: ''
      },
      {
        type: 'rangePicker',
        label: 'public.CreateDate',
        attr: 'applyTime',
        value: [],
      },
      {
        type: 'doubleInput',
        label: 'teleMarketing.no47',
        attr: ['unorderedDayMim','unorderedDayMax'],
        value: [],
      }
    ];
    const searchData2=[
      {
        type: 'input',
        label: 'public.userTel',
        attr: 'phone',
        value: ''
      },
      {
        type: 'input',
        label: 'public.name',
        attr: 'name',
        value: ''
      },
      {
        type: 'input',
        label: 'public.no2',
        attr: 'idCard',
        value: ''
      },
      {
        type: 'rangePicker',
        label: 'teleMarketing.no48',
        attr: 'orderTime',
        value: [],
      },
      {
        type: 'select',
        attr: 'isFollow',
        label: 'teleMarketing.no9',
        option: this.$store.state.options.isOverdue_option, // 订单状态下拉选框信息
        value: '',
        langFlag: true,
      },
      {
        type: 'select',
        attr: 'adminId',
        label: 'teleMarketing.no7',
        option: [],
        value: '',
        langFlag: false,
      },
      {
        type: 'select',
        attr: 'phoneResult',
        label: 'auditDetail.no43',
        option: this.$store.state.options.telResult_select, 
        value: '',
        langFlag: true,
      },
      {
        type: 'select',
        attr: 'isBorrow',
        label: 'teleMarketing.no14',
        option: this.$store.state.options.loanIntention_status, 
        value: '',
        langFlag: true,
      },
      {
        type: 'rangePicker',
        label: 'teleMarketing.no10',
        attr: 'followupTime',
        value: [],
      },
      {
        type: 'doubleInput',
        label: 'teleMarketing.no49',
        attr: ['loanCountMin','loanCountMax'],
        value: [],
      },
      {
        type: 'doubleInput',
        label: 'teleMarketing.no50',
        attr: ['unfollowupDayMim','unfollowupDayMax'],
        value: [],
      }
    ]
    return {
      flag: true,
      loadFlag: true,
      searchData1:searchData1,
      searchData2:searchData2,
      activeName:'1',
      unDisFormInline:{
        type:1,
        idCard: '',
        name: '',
        phone: '',
        createTimeBegin:'',
        createTimeEnd:'',
        unorderedDayMim:'',
        unorderedDayMax:'',
      },//未分配查询字段
      formInline: { //已分配查询字段
        type:2,
        idCard: '',
        name: '',
        phone: '',
        orderTimeBegin:'',
        orderTimeEnd:'',
        adminId:'',
        isFollow:'',
        phoneResult:'',
        isBorrow:'',
        followupTimeBegin:'',
        followupTimeEnd:'',
        loanCountMin:'',
        loanCountMax:'',
        unfollowupDayMim:'',
        unfollowupDayMax:''
      },
      pagination1: {//未分配列表页码
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      pagination2: {//已分配列表页码
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      listData1: [],// 未分配列表数据
      listData2: [],// 已分配列表数据
      currentPage2: 1, // 当前页下标
      currentPage3: 1, // 当前页下标
      pageTotal2: 0, // 分页总数
      pageTotal3: 0, // 分页总数
      adminOptions: [], // 电销员
      redeployFlag: false, // 转派弹窗开关
      redeployStatus: '', // 转派弹窗客服下拉框对应数据
      multipleSelection1: [], // 可勾选表格选中项
      multipleSelection2: [], // 可勾选表格选中项
      orderIds: [], // 选中的订单ID数组
      orderType: '', // 订单类型
      reason: '',// 转派原因描述
      pageTotal1: 0, // 个性分单分页总数
      currentPage1: 0, // 个性分单分页总数
      isshowselfdom: '',// 个性分单按钮是否展示
      selfdomFlag: false,// 个性分单弹窗
      tableData1: [],// 个性分单列表信息数据
      tableData2: [],// 个性分单列表信息数据
      tableData3: [],// 电销记录
      noallotOrdersType: '',// 个性平均分单未分配总量
      noallotOrdersNew: 0,// 个性平均分单未分配总量
      noallotOrdersOld: 0,// 个性平均分单未分配总量
      inputValueNew: {},// 个性分单分配的值新客
      inputValueOld: {},// 个性分单分配的值老客
      allocationNumber1: [],// 个性分单新客分单集合
      allocationNumber2: [],// 个性分单老客分单集合
      addDataFlag: false,
      detailFlag: false,
      detailData:{},
      fileList: [],
      fileReader: '',
      base64Str: '',
      fileType: '',
      putExcelUrl:this.$action.telemarket_listExport, //导出接口？？
      fileAction:this.$action.fileUpload,//上传文件地址
      updateUrl:'',//上传数据后返回的地址
      distributionIds:[],//分单选中ids
      addDataAdmin:'',//添加数据电销员
    }
  },
  methods: {
    clearChannel(){
      this.formInline.regChannel = '';
    },
    listHandleSizeChange1 (val) {// 未分配每页条数变化时操作
      this.pagination1.pageSize = val;
      this.getListData1();
    },
    listHandleCurrentChange1 (val) { // 未分配分页按钮点击操作
      this.pagination1.current = val;
      this.getListData1();
    },
    listHandleSizeChange2 (val) {// 已分配每页条数变化时操作
      this.pagination2.pageSize = val;
      this.getListData2();
    },
    listHandleCurrentChange2 (val) { // 已分配分页按钮点击操作
      this.pagination2.current = val;
      this.getListData2();
    },
    search1(search) { // 搜索
        this.unDisFormInline=search;
        console.log(this.unDisFormInline.type);
        this.unDisFormInline.createTimeBegin=search.applyTime?search.applyTime[0]:'';
        this.unDisFormInline.createTimeEnd=search.applyTime?search.applyTime[1]:'';
        if (this.flag) {
          this.flag = false;
          this.pagination1.current = 1;
          this.getListData1();
        }
    },
    search2(search) { // 搜索
        this.formInline=search;
        this.formInline.orderTimeBegin=search.orderTime?search.orderTime[0]:'';
        this.formInline.orderTimeEnd=search.orderTime?search.orderTime[1]:'';
        this.formInline.followupTimeBegin=search.followupTime?search.followupTime[0]:'';
        this.formInline.followupTimeEnd=search.followupTime?search.followupTime[1]:'';
        if (this.flag) {
          this.flag = false;
          this.pagination2.current = 1;
          this.getListData2();
        }
    },
    getListData1 () { // 未分配获取列表数据
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination1.current,
        pageSize:this.pagination1.pageSize,
        param: {
          type:1,
          ...this.unDisFormInline
        }       
      }
      this.$axios.post(this.$action.telemarket_list, option).then(res => {
        this.flag = true;
        if (res.code == 200) {
          this.listData1 = res.data.list;
          this.pagination1.total = res.data.total;
        }else{
          this.$globalMsg.error(res.message)
        }
        this.loadFlag = false;
      })
    },
    getListData2 () { // 已分配获取列表数据
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination2.current,
        pageSize:this.pagination2.pageSize,
        param: {
          type:2,
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.telemarket_list, option).then(res => {
        this.flag = true;
        if (res.code == 200) {
          this.listData2 = res.data.list;
          this.pagination2.total = res.data.total;
        }else{
          this.$globalMsg.error(res.message)
        }
        this.loadFlag = false;
      })
    },
    selectDetail (id,name, phone) { // 查看详情操作
      this.detailData.name = name;
      this.detailData.phone = phone;
      this.getDetailTable(id);
    },
    getDetailTable(id){
      let option = {
        pageNum:this.currentPage3,
        pageSize:'10',
        param:{
          marketId:id
        }
      };
      this.$axios.post(this.$action.telemarket_listLog, option).then(res => {
        if (res.code == 200) {
          this.tableData3 = res.data.list;
          this.pageTotal3 = res.data.total;
          this.detailFlag = true;
        }else{
          this.$globalMsg.error(res.message)
        }
      })
    },
    handleCurrentChange3(val){
      this.currentPage3 = val;
      this.getDetailTable()
    },
    handleSelectionChange1 (val) { // 表格选中项数据
      this.multipleSelection1 = val;
    },
    handleSelectionChange2 (val) { // 表格选中项数据
      this.multipleSelection2 = val;
    },
    todayRedeploy () { // 转派按钮点击操作     
      if (this.orderIds == '') {
        this.$globalMsg.error(this.$t('loanAfterManage.selFirst'));
      }  else {
        this.redeployFlag = true;
      }
    },
    redeployClose () {
      this.redeployFlag = false;
      this.redeployStatus = '';
      this.reason = '';
    },
    joinType () { // 订单转派弹窗对应数据处理
      let arr = [];
      this.multipleSelection2.forEach(value => {
        arr.push(value.id);
      })
      this.orderIds = arr;
    },
    redeploySubmit () { // 转派确认操作
      if (this.redeployStatus == '') {
        this.$globalMsg.error(this.$t('public.placeholder')+this.$t('teleMarketing.no7'));
        return;
      }
      if (this.reason == '') {
        this.$globalMsg.error(this.$t('loanAfterManage.placeholder'));
        return;
      }
      if (this.flag) {
        this.flag = false;
        let option = {
          param: {
            adminId: this.redeployStatus,
            ids: this.orderIds,
            remark: this.reason
          }
        };
        this.$axios.post(this.$action.telemarket_listTransfer, option).then(res => {
          this.flag = true;
          if (res.code == 200) {
            this.$globalMsg.success(this.$t('message.success'));
          } else {
            this.$globalMsg.error(res.message);
          }
          this.getListData2();
          this.redeployClose();
        })
      }
    },
    // getchannel(){ // 获取渠道下拉框数据
    //   this.options1 = []
    //   let option = {
    //     header: {
    //       ...this.$base,
    //       action: this.$store.state.actionMap.PHONEMARKET0011,
    //       'sessionid': this.sessionid
    //     }
    //   }
    //   this.$axios.post('', option).then(res => {
    //     this.flag = true;
    //     if (res.data.header.code == 0) {
    //       let arr = res.data.data;
    //       arr.forEach(value=>{
    //         this.options1.push({value,label:value})
    //       })
    //     }
    //   })
    // },
    distribution(){// 个性分单按钮点击操作
      this.distributionIds=[];
      this.multipleSelection1.forEach(value => {
        this.distributionIds.push(value.id);
      })
      if (this.distributionIds == '') {
        this.$globalMsg.error(this.$t('teleMarketing.no69'));
      } else {
        this.selfdomFlag = true;
        this.noallotOrdersNew = this.distributionIds.length;
        this.getselfdomTable();
      }   
    },
    getselfdomTable(){// 获取个性分单列表
      let option = {
        param: {}       
      }
      this.$axios.post(this.$action.telemarket_dispatchList, option).then(res => {
        if (res.code == 200) {
          this.tableData1=res.data;
          this.tableData2 = this.tableData1.slice(0,10);  
        }else{
          this.$globalMsg.error(res.data.message)
        }
      })
    },
    handleCurrentChange1 (val) { // 个性分单分页按钮操作
      this.currentPage1 = val;
      this.tableData2 = this.tableData1.slice((val-1)*10,val*10);
    },
    selfdomSure(){// 个性分单确认按钮
      let sum1 = 0;
      let arr = [];
      let adminIds=[];
      // this.distributionIds=[1,2,3,4,5,6,7,8];
      // this.inputValueNew={'11':5,'22':'',"33":3};
      let orderIds=this.distributionIds;
      for (var index in this.inputValueNew){
        console.log(index);
        if(this.inputValueNew[index]!=''){
          sum1+=Number(this.inputValueNew[index]);
          adminIds.push(index);
          arr.push(orderIds.splice(0,this.inputValueNew[index]))
          // arr.push({adminId:index,distributeCount:Number(this.inputValueNew[index])});
        }
      }
      console.log(adminIds);
      console.log(arr);
      if(arr==''){
        this.$globalMsg.error(this.$t('OutsourcedManage.no20'));
        return false;
      }
      if(sum1>Number(this.noallotOrdersNew)){
        this.$globalMsg.error(this.$t('OutsourcedManage.no19'));
        return false;
      }
      let option = {
        param: {
          ids:arr,
          adminIds:adminIds
        }       
      }
      this.$axios.post(this.$action.telemarket_dispatch, option).then(res => {
        if (res.code == 200) {
          this.$globalMsg.success(this.$t('message.success'));
          this.getListData1()
        } else {
          this.$globalMsg.error(res.message);
        }
      })
      this.inputValueNew = {};
      this.selfdomFlag = false;
    },
    showaddData(){
      this.addDataFlag = true;
    },
    addExcel(){
      let option = {
        param:{
          type:this.activeName,
          adminId:this.activeName=='2'?this.addDataAdmin:'',
          fileType: this.fileType,
          fileBase64: this.base64Str,
        }
      }
      this.$axios.post(this.$action.telemarket_listImport, option).then(res => {
        if (res.code == 200) {     
          this.$globalMsg.success(res.message);
          this.getListData1()
          this.getListData2()
          this.addDataFlag = false;
          this.fileList = [];             
            // this.getchannel()
        } else {
          this.$globalMsg.error(res.message);
        }
      })  
        
    },
    downExcel(){     
      this.$axios.post(this.$action.telemarket_listTemplate+this.activeName).then(res => {
        if (res.code == 200) {
            let title = res.data.titles;
            let fields = [];
            let data = [];
            let filename=res.data.fileName;
            this.$export2Excel(title,fields,data,filename+'.xlsx');
        }
      })  
    },
    // 上传文件相关
    httpRequest (options) {
      let file = options.file;
      // console.log(file.name.split('.')[file.name.split('.').length-1])
      if (file) {
        this.fileReader.readAsDataURL(file);
      }
      this.fileReader.onload = () => {
        let base64Str = this.fileReader.result;
        this.base64Str = this.fileReader.result.split(",")[1];
        this.fileType = file.name.split('.')[file.name.split('.').length-1]
        options.onSuccess("123", file);
      };
    },
    removeHandler (file) {
      this.fileList=this.fileList.filter(value=>{
        return file.uid!==value.uid;
      })
    },
    beforeUpload (file) {
      if (file.type!='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'||file.size / 1024 / 1024>20) {
        this.$globalMsg.error(this.$t('teleMarketing.no72'));
        return false;
      }
      if (this.fileList.length >= 1) {
        this.$globalMsg.error(this.$t('teleMarketing.no73')+'1');
        return false;
      }
      
      // if (!isIMAGE) {
      //   this.$globalMsg.error('文件类型错误');
      //   return false;
      // }
    },
    uploadSuccess (res, file) {
      let data = res;
      this.fileList.push({data,uid:file.uid})
    },
    // handleAvatarSuccess(res, file) {
		// 	this.$globalMsg.success(this.$t('message.success'))
		// 	this.updateUrl = res.data;
    // },
  },
  watch: {
    multipleSelection2 () {
      this.joinType()
    },
    // redeployFlag () {
    //   if(!this.redeployFlag){
    //     this.redeployClose();
    //   }
    // }
  },
  mounted () {
    this.fileReader = new FileReader();
    this.telemarketMem().then(arr=>{// 获取在职电销员
      this.adminOptions=arr;
      this.searchData2[5].option=arr;
    })
    this.getListData1();
    this.getListData2();
    // this.getchannel();// 获取渠道来源
  }
}
</script>

<style scoped lang="scss">
  div .upload-demo .el-upload--text{
    width: auto;
  }
  .mr20{
    margin-right: 20px;
  }
  .mb5{
    margin-bottom: 6px;
  }
  .box{
    .el-upload--text {
      width: 100px;
      height: auto;
    }
  }
  .el-upload {
    width: auto;
    height: auto;
  }
  .upload{
    background-color: #3a8ee6;
    display: inline-block;
    color: #ffffff;
    padding: 8px 6px;
    text-align: center;
    border-radius: 5px;
  }
  .mt-10{
    margin-top: -20px;
    margin-bottom: 6px;
  }
</style>
